#include "StdAfx.h"
#include "PickableItem.h"
#include "Level.h"
#include "CubePhysX.h"
#include "NxActor.h"
#include "Character.h"
#include "NxShape.h"
#include "Sphere.h"

PickableItem::PickableItem(Level* pLevel,int id,D3DXVECTOR3 position,LevelElement* object, bool rotate):
	m_ID(id),
	m_Position(position),
	m_pObject(object),
	m_Rotate(rotate),
	m_yRot(0)
{
	m_pLevel = pLevel;	
}

PickableItem::~PickableItem(void)
{
	delete m_pObject;
	delete m_pTrigger;
}


void PickableItem::Tick(const InputState& inputState)
{
	if(m_Rotate)
	{
		m_pObject->ResetWorldMatrix();
		D3DXVECTOR3 rotator(0.0f,m_yRot,0.0f);
		m_pObject->Rotate(rotator);
		m_pObject->Translate(m_Position);
		//Deze waarde moet nog aangepast worden
		m_yRot += 0.00033f; //57,29577951;
	}
}
void PickableItem::Draw(const RenderContext* context, ID3D10ShaderResourceView* shadowdepthmap) {
	if ( m_pObject )
		m_pObject->Draw(context);
}

void PickableItem::Initialize(ContentManager* manager)
{
	m_pObject->SetParent(m_pLevel);
	m_pObject->Initialize(manager);
	m_pObject->Translate(m_Position);

	m_pTrigger = new CubePhysX(m_pLevel, 1.5f, 1.5f, 1.5f,D3DXCOLOR(1,1,1,1),CubePhysX::GHOST);
	m_pTrigger->Translate(m_Position);

	m_pTrigger->GetActor()->userData = this;
}

void PickableItem::OnTriggerEnter(Character* player)
{
	//player->AddToInventory(this);
	m_pLevel->RemoveChild(this);

	m_pTrigger->GetActor()->raiseActorFlag(NX_AF_DISABLE_COLLISION);
}

void PickableItem::OnTriggerExit(Character* player)
{
	
}

void PickableItem::DisableTrigger()
{

}